package com.example.study.controller;

import com.example.study.dao.User;
import com.example.study.service.UserService;
import com.example.study.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping(value = "/api/user")
public class LoginController
{
//    @Autowired
//    private UserService userService;
//
//    @Autowired
//    private StringRedisTemplate redisTemplate;
//
//    @GetMapping("/login")
//    public JsonResult login(HttpServletRequest request,  @RequestParam(value = "username") String username) throws Exception {
//        User user = userService.getUserByName(username);
//        if (user != null)
//        {
//            HttpSession session = request.getSession();
//            session.setAttribute("loginUserId", user.getId());
//            redisTemplate.opsForValue().set("loginUser:" + user.getId(), session.getId());
//
//            return new JsonResult<>(user,"成功");
//        }
//        else
//        {
//            throw new Exception("账户名或密码错误！");
//        }
//    }
//
//    @RequestMapping(value = "/getUserInfo")
//    public JsonResult get(String userId) throws Exception {
//        User user = userService.getById(userId);
//        if (user != null)
//        {
//            return new JsonResult<>(user, "查询成功！");
//        }
//        else
//        {
//            throw new Exception( "用户不存在！");
//        }
//    }
}